public class test3 {
    public static int max = Integer.MIN_VALUE;
    public int maxPathSum (TreeNode root) {
        getResult(root);
        return max;
    }
    public static int getResult(TreeNode treeNode){
        if(treeNode == null)
            return 0;

        int leftMax = Math.max(getResult(treeNode.left),0); //只要是正数,加上一定就是增加的
        int rightMax = Math.max(getResult(treeNode.right),0);

        int flag = treeNode.val+leftMax+rightMax;
        max = Math.max(max,flag);

        return treeNode.val+Math.max(rightMax,leftMax);//返回最新的最大值
    }
}
